home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / telecomm / zmdm.zoo / main.c < prev    next >
C/C++ Source or Header  |  1991-04-27  |  16KB  |  887 lines

  1. /*
  2.  *     Main Module
  3.  *
  4.  *    Jwahar Bammi
  5.  *     bang:   {any internet host}!dsrgsun.ces.CWRU.edu!bammi
  6.  *     domain: bammi@dsrgsun.ces.CWRU.edu
  7.  *    GEnie:    J.Bammi
  8.  */
  9.  
  10. #include "config.h"
  11.  
  12. #include "zmdm.h"
  13. #include "common.h"
  14.  
  15. #ifndef Vsync             /* Atari forgot these in osbind.h */
  16. #define Vsync()    xbios(37)
  17. #endif
  18.  
  19. #define    esc    27
  20. #define cr    0x0d
  21. #define mvto(r,c)    EscSeq('Y');Bconout(2,r+040);Bconout(2,c+040)
  22.  
  23. #ifdef PHONES    /* common to this module and phone.c */
  24. char    *PhoneFile;
  25. #endif
  26.      /* Globals belonging to this module only */
  27.  
  28. int    rs232 = 1,        /* Ports */
  29.         console = 2;
  30. int    speed,              /* rs232 setup parameters */
  31.       flowctl = 0,
  32.     ucr = -1,
  33.     rsr = -1,
  34.     tsr = -1,
  35.     scr = -1;
  36. static int duplex = 0;        /* full duplex_p */
  37.  
  38. #ifdef FLOW_CTRL
  39. /*
  40.  * setFlow() - set rs232 flow control
  41.  */
  42. #ifndef REMOTE
  43. void setFlow ()
  44. {
  45.     long conin;
  46.     int ch, i;
  47.     char cc[4] = " 0=";
  48.  
  49.     Bconws("Flow control: ");
  50.     EscSeq('p');
  51.     for (i=0; i<4; i++) {
  52.         Bconws(cc);
  53.         Bconws(vflows[i].sflow);
  54.         cc[1]++;
  55.     }
  56.     Bconws("\r\n");
  57.     EscSeq('q');
  58.     Bconout(2, '\t');
  59.     EscSeq('p');
  60.     Bconws("What type==>");
  61.     EscSeq('q');
  62.     
  63.     conin = Bconin(console);    /* get flow type */
  64.     if ((conin & 0x00FF0000L) == 0x00610000L)
  65.     {
  66.         his_screen();    /* hit UNDO */
  67.          ResetIoBuf();
  68.         finish();
  69.     }
  70.     ch = (conin & 0x007f) - '0';
  71.     Bconout(2, ' ');
  72.  
  73.     if ((ch >= 0) && (ch < i))
  74.         flowctl = ch;
  75.  
  76.     Bconws(FLOW_STRING(flowctl));
  77.     Bconws("\r\n");
  78.     Rsconf(-1, flowctl, -1, -1, -1, -1);
  79. }
  80. #else
  81. void setFlow ()
  82. {
  83.     long conin;
  84.     int ch, i;
  85.     char cc[4] = " 0=";
  86.  
  87.     Bauxws("Flow control: ");
  88.     for (i=0; i<4; i++) {
  89.         Bauxws(cc);
  90.         Bauxws(vflows[i].sflow);
  91.         cc[1]++;
  92.     }
  93.     Bauxws("\r\n");
  94.     Bconout(1, '\t');
  95.     Bauxws("What type==>");
  96.     
  97.     conin = Bconin(1);    /* get flow type */
  98.     if (((int)(conin & 0x007f) & CTRL('U')) == CTRL('U'))
  99.     {
  100.         his_screen();    /* hit UNDO */
  101.          ResetIoBuf();
  102.         finish();
  103.     }
  104.     ch = (conin & 0x007f) - '0';
  105.     Bconout(1, ' ');
  106.  
  107.     if ((ch >= 0) && (ch < i))
  108.         flowctl = ch;
  109.  
  110.     Bauxws(FLOW_STRING(flowctl));
  111.     Bauxws("\r\n");
  112.     Rsconf(-1, flowctl, -1, -1, -1, -1);
  113. }
  114. #endif /* REMOTE */
  115. #endif /* FLOW_CTRL */
  116.         
  117. /*
  118.  * setBaud() - set rs232 port speed
  119.  */
  120. #ifndef REMOTE
  121. void setBaud ()
  122. {
  123.       long conin;
  124.     int ch, i;
  125.     char cc[4] = " 0=";
  126.     
  127.     Bconws("Baud rate:");
  128.     EscSeq('p');
  129.     for (i=0; vbauds[i].sbaud != NULL; i++) {
  130.         Bconws(cc);
  131.         Bconws(vbauds[i].sbaud);
  132.         cc[1]++;
  133.     }
  134.     Bconws("\r\n");
  135.     EscSeq('q');
  136.     Bconout(2, '\t');
  137.     EscSeq('p');
  138.     Bconws("What speed==>");
  139.     EscSeq('q');
  140.     
  141.     conin = Bconin(console);    /* get speed */
  142.     if ((conin & 0x00FF0000L) == 0x00610000L)
  143.     {
  144.         his_screen();
  145.         ResetIoBuf();
  146.         finish();
  147.     }
  148.     ch = (conin & 0x007f) - '0';
  149.     Bconout(2, ' ');
  150.  
  151.     if ((ch >= 0) && (ch < i))
  152.         speed = ch;
  153.     else
  154.          speed = getbaud();
  155.  
  156.     Bconws(BAUD_STRING(speed));
  157.     Baudrate = BAUD_RATE(speed);
  158.  
  159.      Bconws(" Baud\r\n");
  160.     
  161.     /* Set new Baud rate */
  162.  
  163. /*    Txoff(); */
  164. #ifndef    HIBAUD
  165.     Rsconf(vbauds[speed].ibaud, flowctl, ucr, rsr, tsr, scr);
  166. #else
  167.     {
  168.     register char *mfp_ptr = (char *) 0xfffffa00L;
  169.     conin=Super(0L);
  170.     mfp_ptr[0x29] &= 0x7f;    /* Clear divide by 16 mode */
  171.     mfp_ptr[0x1d] &= 0xf0;    /* Stop TImer D */
  172.     for (mfp_ptr[0x25] = cbauds[speed].tdd;    /* Load Timer D data */
  173.         mfp_ptr[0x25] != cbauds[speed].tdd;
  174.         mfp_ptr[0x25] = cbauds[speed].tdd);
  175.     mfp_ptr[0x1d] |= cbauds[speed].tdc;    /* Set Timer D mode */
  176.     Super(conin);
  177.     }
  178. #endif
  179.     
  180.     Vsync(); Vsync();
  181. /*    Txon(); */    
  182. }
  183. #else
  184. void setBaud ()
  185. {
  186.     char ch;
  187.     long conin;
  188.     
  189.     Bauxws("Baud rate: ");
  190.     Bauxws("0=19200 1=9600, 2=4800, 3=2400, 4=1200, 5=300\r\n");
  191.     Bconout(1, '\t');
  192.     Bauxws("What speed==>");
  193.     
  194.     conin = Bconin(1);    /* get speed */
  195.     if (((int)(conin & 0x007f) & CTRL('U')) == CTRL('U'))
  196.     {
  197.         his_screen();
  198.         ResetIoBuf();
  199.         finish();
  200.     }
  201.     ch = (char) (conin & 0x007f);
  202.     Bconout(1, ' ');
  203.     switch (ch)
  204.     {
  205.         case '0':        /* 19200 */
  206.         speed = 0;
  207.         Bauxws("19200");
  208.         Baudrate = 19200;
  209.         break;
  210.         
  211.         case '1':
  212.         speed = 1;    /* 9600 */
  213.         Bauxws("9600");
  214.         Baudrate = 9600;
  215.         break;
  216.         
  217.         case '2':
  218.         speed = 2;    /* 4800 */
  219.         Bauxws("4800");
  220.         Baudrate = 4800;
  221.         break;
  222.         
  223.         case '3':
  224.         speed = 4;    /* 2400 */
  225.         Bauxws("2400");
  226.         Baudrate = 2400;
  227.         break;
  228.         
  229.         case '4':
  230.         speed = 7;    /* 1200 */
  231.         Bauxws("1200");
  232.         Baudrate = 1200;
  233.         break;
  234.         
  235.         case '5':
  236.         speed = 9;    /* 300 */
  237.         Bauxws("300");
  238.         Baudrate = 300;
  239.         break;
  240.  
  241.         default:
  242.         speed = getbaud();
  243.         Bauxws(BAUD_STRING(speed));
  244.         Baudrate = BAUD_RATE(speed);
  245.     }
  246.     Bauxws(" Baud\r\n");
  247.     
  248.     /* Set new Baud rate */
  249.  
  250. /*    Txoff(); */
  251.     Rsconf(speed, flowctl, ucr, rsr, tsr, scr);
  252.     Vsync(); Vsync();
  253. /*    Txon(); */
  254.  
  255.     
  256. }
  257. #endif /* REMOTE */
  258.  
  259. /*
  260.  * help() - display help info and menu
  261.  */
  262. #ifndef REMOTE
  263. void help ()
  264. {
  265.     register long conin;
  266.     register int x;
  267.     extern char *r_filename();
  268.     
  269.     my_screen();        /* Switch to my screen memory */
  270.     EscSeq('v');        /* wrap at end of line */
  271.     EscSeq('E');        /* clear screen */
  272.     
  273.     mvto(2,11);
  274.     EscSeq('p');
  275.     Bconws("ZMDM Version: ");
  276.     Bconws(ZMDMVERSION);
  277.     EscSeq('q');
  278.     EscSeq('p');
  279.     x =(int) strlen(COMPILER);
  280.     x = (80 - x)/2;
  281.     mvto(3,x);
  282.     Bconws(COMPILER);
  283.     EscSeq('q');
  284.     mvto(5,21);
  285.     Bconws("bammi@cadence.com\r\n\n");
  286.  
  287.     /* Put up menu */
  288.     Bconws("\r\n\t");
  289.     EscSeq('p');        /* reverse video */
  290.     Bconws("Undo");
  291.     EscSeq('q');        /* quit reverse video */
  292.     Bconws(" to exit.\r\n");
  293.     
  294.     Bconws("\t");
  295.     EscSeq('p');        /* reverse video */
  296.     Bconws("Help");
  297.     EscSeq('q');        /* quit reverse video */
  298.     Bconws(" for this message.\r\n");
  299.  
  300.     Bconws("\t");
  301.     EscSeq('p');        /* reverse video */
  302.     Bconws("Escape");
  303.     EscSeq('q');        /* quit reverse video */
  304.     Bconws(" to send a break.\r\n");
  305.     
  306.     Bconws("\t");
  307.     EscSeq('p');        /* reverse video */
  308.     Bconws("T or t");
  309.     EscSeq('q');        /* quit reverse video */
  310.     Bconws(" to do file transfers and local functions.\r\n");
  311.  
  312. #ifdef PHONES
  313.     Bconws("\t");
  314.     EscSeq('p');        /* reverse video */
  315.     Bconws("P or p");
  316.     EscSeq('q');        /* quit reverse video */
  317.     Bconws(" for Phone services.\r\n");
  318. #endif
  319.  
  320.     if(rez == 2)
  321.     {
  322.         Bconws("\t");
  323.         EscSeq('p');        /* reverse video */
  324.         Bconws("H or h");
  325.         EscSeq('q');        /* quit reverse video */
  326.         Bconws(" for Hi Rez Toggle (25/50 Lines).\r\n");
  327.     }
  328.  
  329.     Bconws("\t");
  330.     EscSeq('p');        /* reverse video */
  331.     Bconws("I or i");
  332.     EscSeq('q');        /* quit reverse video */
  333.     Bconws(" to Invert screen colors.\r\n");
  334.  
  335.     Bconws("\t");
  336.     EscSeq('p');        /* reverse video */
  337.     Bconws("D or d");
  338.     EscSeq('q');        /* quit reverse video */
  339.     Bconws(" to toggle duplex.\r\n");
  340.     
  341.     Bconws("\t");
  342.     EscSeq('p');        /* reverse video */
  343.     Bconws("Return");
  344.     EscSeq('q');        /* quit reverse video */
  345.     Bconws(" to do nothing.\r\n");
  346.     
  347. #ifdef    FLOW_CTRL
  348.     Bconws("\t");
  349.     EscSeq('p');        /* reverse video */
  350.     Bconws("F or f");
  351.     EscSeq('q');        /* quit reverse video */
  352.     Bconws(" to set flow control.  Currently is ");
  353.     EscSeq('p');
  354.     Bconws(FLOW_STRING(flowctl));
  355.     Bconws(".\r\n");
  356.     EscSeq('q');
  357. #endif
  358.  
  359.     Bconws("\t");
  360.     EscSeq('p');        /* reverse video */
  361.     Bconws("B or b");
  362.     EscSeq('q');        /* quit reverse video */
  363.     Bconws(" to set baud rate.     Currently is ");
  364.     EscSeq('p');
  365.     Bconws(BAUD_STRING(speed));
  366.     Bconws(" Baud.\r\n\r\n");
  367.     EscSeq('q');
  368.  
  369.     /* get response */
  370.     conin = Bconin(console);
  371.  
  372.     if ((conin & 0x00FF0000L) == 0x00610000L)
  373.     {
  374.         /* He hit <UNDO> */
  375.         his_screen();
  376.         ResetIoBuf();
  377.         finish();
  378.     }
  379.     
  380.     switch((int)(conin & 0x007f))
  381.     {
  382.         case 'B':
  383.         case 'b':
  384.         /* Set baud rate */
  385.         setBaud();
  386.         break;
  387.  
  388. #ifdef    FLOW_CTRL
  389.         case 'F':
  390.         case 'f':
  391.         /* Set flow control */
  392.         setFlow();
  393.         break;
  394. #endif
  395.         
  396.         case 'T':
  397.         case 't':
  398.             EscSeq('E');        /* clear screen */
  399.  
  400.             /* Set no flow Control */
  401. #if 0
  402. #ifdef FLOW_CTRL
  403.             Rsconf(-1,0,-1,-1,-1,-1);
  404.             Vsync(); Vsync();
  405.  
  406. #endif
  407. #endif
  408.         /* Go do transfers */
  409.         transfer();
  410.             
  411. #if 0
  412. #ifdef FLOW_CTRL
  413.             /* Flow Control On */
  414. /*            Txoff(); */
  415.             Rsconf(-1,flowctl,-1,-1,-1,-1);
  416.             Vsync(); Vsync();
  417. /*            Txon(); */
  418. #endif
  419. #endif
  420.         his_screen();
  421.         return;
  422.         
  423.         case '\033':
  424.         /* Send a break */
  425.         sendbrk();
  426.         his_screen();    /* Don't wait for the key hit */
  427.  
  428.         return;
  429.  
  430.           case 'd':
  431.           case 'D':
  432.         duplex ^= 1;
  433.         his_screen();
  434.         return;
  435.         
  436.         case 'i':
  437.         case 'I':
  438.         /* Invert screen colors */
  439.         his_screen();
  440.         if(scolor == 0)
  441.         {
  442.             EscSeq('b');    /* Foreground color 0 */
  443.             Bconout(2, 0);
  444.             EscSeq('c');    /* Background color 1 */
  445.             Bconout(2, 1);
  446.             scolor = 1;
  447.         }
  448.         else
  449.         {
  450.             EscSeq('b');